/*
package com.wtp.wallpaper.config;

import co.elastic.clients.elasticsearch.ElasticsearchClient;
import co.elastic.clients.json.jackson.JacksonJsonpMapper;
import co.elastic.clients.transport.rest_client.RestClientTransport;
import org.apache.http.HttpHost;
import org.apache.http.auth.AuthScope;
import org.apache.http.auth.UsernamePasswordCredentials;
import org.apache.http.client.CredentialsProvider;
import org.apache.http.impl.client.BasicCredentialsProvider;
import org.elasticsearch.client.RestClient;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.elasticsearch.client.ClientConfiguration;

@Configuration
public class ElasticConfig {

    // Spring Data自动配置（网页5）
    @Bean
    @ConfigurationProperties(prefix = "spring.elasticsearch")
    public ClientConfiguration clientConfiguration() {
        return ClientConfiguration.builder().connectedToLocalhost().build();
    }

    // 官方客户端配置（网页1）
    @Bean
    public ElasticsearchClient elasticsearchClient(ClientConfiguration config) {

        RestClient restClient = RestClient.builder(
                new HttpHost(config.getHosts().get(0).getHostName(),
                        config.getHosts().get(0).getPort(),
                        config.getHosts().get(0).getProtocol())
        ).setHttpClientConfigCallback(httpClientBuilder -> {
            // 添加认证（网页2）
            CredentialsProvider credentials = new BasicCredentialsProvider();
            credentials.setCredentials(AuthScope.ANY,
                new UsernamePasswordCredentials("elastic", "yourpassword"));
            return httpClientBuilder.setDefaultCredentialsProvider(credentials);
        }).build();

        return new ElasticsearchClient(new RestClientTransport(
            restClient,
            new JacksonJsonpMapper()
        ));
    }
}*/
